{include file="common/header"}
<div id="app" v-cloak>
    <el-curd 
        ref="curd"
        :field="field" 
        :batch="[{title: '账号状态', field: ['status']}]"
        :table-sort="{prop: 'create_time', order: 'desc'}"
        :search-status="[{label: '正常', value: 1}, {label: '屏蔽', value: 0}]"
        search-keyword="请输入邮箱/手机/昵称/ID搜索"
        save-title="新增虚拟会员"
        :preview-authority="true"
        :delete-authority="false"
        form-label-width="110px">
        <template v-slot:dropdown="row">
            <li 
                v-if="authority.indexOf(setEmailUrl) !== -1"
                @click="openData(row, ['email'], '更换邮箱号', setEmailUrl)">
                更换邮箱号
            </li>
            <li 
                v-if="authority.indexOf(setMobileUrl) !== -1"
                @click="openData(row, ['mobile'], '更换手机号', setMobileUrl)">
                更换手机号
            </li>
            <li 
                v-if="authority.indexOf(setPasswordUrl) !== -1"
                @click="openData(row, ['password'], '修改密码', setPasswordUrl)">
                修改密码
            </li>
            <li 
                v-if="authority.indexOf(setStatusUrl) !== -1"
                @click="openData(row, ['status'], '状态账号', setStatusUrl)">
                账号状态
            </li>
            <li 
                v-if="authority.indexOf(setBalanceUrl) !== -1"
                @click="openData(row, ['balanceTo'], '余额充值', setBalanceUrl)">
                余额充值
            </li>
            <li 
                v-if="authority.indexOf(setIntegralUrl) !== -1"
                @click="openData(row, ['integralTo'], '积分充值', setIntegralUrl)">
                积分充值
            </li>
        </template>
    </el-curd>
</div>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                setEmailUrl: 'user/email',
                setMobileUrl: 'user/mobile',
                setBalanceUrl: 'user/balance',
                setIntegralUrl: 'user/integral',
                setPasswordUrl:  'user/password',
                setStatusUrl: 'user/status',
                authority: authority,
                field: [
                    {
                        label: '编号', 
                        prop: 'id',
                        table: false,
                    },
                    {
                        prop: 'cover', 
                        label: '会员头像', 
                        table: {
                            label: '',
                            is: 'el-image',
                            width: '60px', 
                        },
                        form: {
                            is: 'el-file-upload',
                            type: '.png,.jpg,.jpeg',
                            default: "{$config.cover}"
                        },
                    },
                    {
                        prop: 'email', 
                        label: '会员邮箱号', 
                        table: {
                            label: '资料信息', 
                            bind: ['mobile'], 
                            sort: true
                        },
                        form: {
                            rules: [
                                {required: true, message: '邮箱不能为空'},
                            ],
                            update: false,
                        },
                    },
                    {
                        prop: 'mobile', 
                        label: '会员手机号', 
                        table: false,
                        form: {
                            rules: [
                                {required: true, message: '手机号不能为空'},
                            ],
                            update: false,
                        },
                    },
                    {
                        prop: 'nickname', 
                        label: '会员昵称', 
                        table: false,
                        form: {
                            rules: [
                                {required: true, message: '昵称不能为空'},
                            ],
                            default: "{$config.nickname}"
                        },
                    },
                    {
                        prop: 'login_count', 
                        label: '登录次数', 
                        table:{sort: true},
                        form: false,
                    },
                    {
                        prop: 'balance', 
                        label: '可用余额',  
                        table:{sort: true},
                        form: {
                            type: 'number',
                            default: 0.00,
                            update: false,
                        }
                    },
                    {
                        prop: 'balanceTo', 
                        label: '充值金额',  
                        table: false,
                        form: {
                            type: 'number',
                            default: 0.00,
                            update: false,
                            save: false,
                            rules: [
                                {required: true, message: '请输入充值金额'},
                            ],
                        }
                    },
                    {
                        prop: 'integralTo', 
                        label: '充值积分',  
                        table: false,
                        form: {
                            type: 'number',
                            default: 0.00,
                            update: false,
                            save: false,
                            rules: [
                                {required: true, message: '请输入积分个数'},
                            ],
                        }
                    },
                    {
                        prop: 'password', 
                        label: '登录密码', 
                        table: false, 
                        form: {
                            type: 'password',
                            placeholder: '不能包含中文字符',
                            rules: [
                                {required: true, message: '新增用户时，密码不能为空'},
                                {pattern: /^[^\u4e00-\u9fa5]+$/, message: '不能包含中文字符'}
                            ],
                            update: false,
                        },
                    },
                    {
                        prop: 'history_integral', 
                        label: '历史积分',  
                        table:{sort: true},
                        form: false
                    },
                    {
                        prop: 'now_integral', 
                        label: '当前积分',  
                        table:{sort: true},
                        form: {
                            type: 'number',
                            default: 0,
                            update: false,
                        }
                    },
                    {
                        prop: 'sex', 
                        label: '会员性别', 
                        table: false,
                        form: {
                            is: 'el-select',
                            default: 0, 
                            child: {is: 'el-option', value:[{label:'男', value:0},{label:'女',value:1}]},
                            colMd: 12
                        }
                    },
                    {
                        prop: 'birthday', 
                        label: '会员生日',
                        table: false,
                        form: {
                            is: 'el-date-picker', 
                            type: 'date', format: 'yyyy-MM-dd', 
                            valueFormat: 'yyyy-MM-dd',
                            colMd: 12
                        },
                    },
                    {
                        prop: 'describe', 
                        label: '简短签名', 
                        table: false,
                        form: {
                            type: 'textarea', 
                            default: "{$config.describe}"
                        },
                    },
                    {
                        prop: 'status',
                        label: '当前状态',  
                        table: { 
                            sort: true
                        }, 
                        form: {
                            is: 'el-switch', 
                            default: 1,
                            update: false,
                        },
                    },
                    {
                        prop: 'reason', 
                        label: '屏蔽原因', 
                        table: false,
                        form: {
                            type: 'textarea',
                            relation: [{prop: 'status', value: 0}],
                        },
                    },
                    {
                        prop: 'create_time', 
                        label: '注册时间', 
                        table:{
                            label: '注册&登录时间',
                            sort: true, 
                            bind: ['login_time']
                        },
                        form: false,
                    },
                ],
            }
        },
        methods: {
            // 打开数据
            openData(row, appoint, title, drawerSave = true) {
                this.$refs.curd.openData(row, appoint, title, drawerSave);
            },
        }
    })
</script>
{include file="common/footer"}